package com.dragon.flow.utils.file;

import java.io.*;

/**
 * 文件处理工具
 */
public class FileUtils {

    /**
     * 根据文件名获取json字符串
     * @param filename
     * @return
     */
    public static String  getJsonByFileName(String packageName,String filename) {
        String jsonStr = null;
        try {
            String fileUrl = System.getProperty("user.dir")+"/prodflow-bpmn-ui-extension/src/main/java/com/dragon/flow/json/"+packageName+"/"+filename;
            File jsonFile = new File(fileUrl);
            FileReader fileReader = new FileReader(jsonFile);
            Reader reader = new InputStreamReader(new FileInputStream(jsonFile), "utf-8");
            int ch = 0;
            StringBuffer sb = new StringBuffer();
            while ((ch = reader.read()) != -1) {
                sb.append((char) ch);
            }
            fileReader.close();
            reader.close();
            jsonStr = sb.toString();
            return jsonStr;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return jsonStr;
    }
}
